package com.laomuji.android.mvvm.utils.google

import android.content.Context
import com.google.android.gms.ads.identifier.AdvertisingIdClient
import kotlinx.coroutines.delay

/**
 * Google AD ID
 * 失败返回空,注意 需要在协程里访问,耗时较久
 * @author laomuji666
 * @since 2024/4/29
 */
class GoogleAdId(val context: Context) {
    private val adInfo = AdvertisingIdClient(context.applicationContext)
    suspend fun getAdvertisingId(): String? {
        //这里的delay仅作为 suspend 占位
        delay(1)
        adInfo.start()
        return adInfo.info.id
    }
}